package com.duoec.dw.lineage.service.impl.desc;

import com.duoec.dw.lineage.dto.TableDescItem;
import com.duoec.dw.lineage.dto.TableDescReaderState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.sql.ResultSet;

/**
 * @author xuwenzhen
 */
@Service
public class FieldTableDescTypeProcessor extends BaseTableDescTypeProcessor {
    private static final Logger logger = LoggerFactory.getLogger(FieldTableDescTypeProcessor.class);
    public static final String TYPE = "field";

    /**
     * 需要处理的type类型
     *
     * @return type类型
     */
    @Override
    public String getType() {
        return TYPE;
    }

    /**
     * 处理一行数据
     *
     * @param state 当前的状态
     * @param rs    当前记录
     * @return 当行数据解析出来的TableDescItem实例
     */
    @Override
    public TableDescItem process(TableDescReaderState state, ResultSet rs) {
        String colName = getColValue(rs, STR_COL_NAME);
        if (StringUtils.isEmpty(colName) || colName.contains("?")) {
            return null;
        }
        TableDescItem item = new TableDescItem();
        item.setColumnName(colName);
        item.setDataType(getColValue(rs, STR_DATA_TYPE));
        item.setComment(getColValue(rs, STR_COMMENT));
        item.setType(TYPE);
        return item;
    }
}
